package emp.dao;

import emp.config.DataSourceConfig;
import emp.entity.Department;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

/**
 * @author 叶枫
 * @date 2024/12/18.
 */


public class DepartmentDao {
    private static DataSourceConfig dataSourceConfig;

    private JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSourceConfig.dataSource());

    //查询所有部门
    public List<Department> list()
    {
        String sql = "select * from department";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Department.class));
    }
    //删除
    public boolean delete(int deptId)
    {
        String sql = "delete from department where deptId=?";
        return jdbcTemplate.update(sql,deptId) > 0;
    }
}
